package uml.class_diagram;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Iterator;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "-----------------------------------------------------" );
        App app = new App();
        
//        StringBuffer sb = app.getFields(APPStructure.class);
        StringBuffer sb = app.getMethods(APPStructure.class);
        System.out.println(sb.toString());
        
    }
    
    public StringBuffer getFields(Class clazz){
    	Field [] fields = clazz.getDeclaredFields();
    	StringBuffer sBuffer = new StringBuffer();
    	for (Field field:fields) {   		
    		sBuffer.append(Modifier.toString(
    				field.getModifiers()))
    				.append(field.getType().getName())
					.append(field.getName())
					.append("\n");
			
//			public:1;
//    		private:2;
//    		defalt:0;
//    		protected:4;
			
		}
		return sBuffer;
    	
    	
    }
    
    public StringBuffer getMethods(Class clazz){
    	Method[] methods = clazz.getMethods();
    	StringBuffer sMethods = new StringBuffer();
    	for (Method method : methods) {
    		
    		if (checkTheMethod(method.getName())) {
				continue;
			}
    		
    		
    		sMethods
			.append(Modifier.toString(method.getModifiers()))
			.append(" ")
			.append(method.getReturnType())
			.append(" ")
			.append(method.getName())
			.append(" ")
			.append(method.getTypeParameters())
			.append("\n");
			
		}	
    	
    	return sMethods;
    }

	private boolean checkTheMethod(String name) {
		if ("".equals(name) || null == name) {
			throw new NullPointerException("The method name can not be null!");
		}
		if ("wait".equals(name)
				|| "equals".equals(name)
				|| "toString".equals(name)
				|| "hashCode".equals(name)
				|| "notify".equals(name)
				|| "notifyAll".equals(name)
				|| name.startsWith("set")
				|| name.startsWith("get")) {
			return true;
		}
		return false;
	}
}
